/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.web.command.component.serializer;

import com.inspur.edp.web.command.component.metadata.BranchCollectionCommandItem;
import com.inspur.edp.web.command.component.metadata.BranchCommandItem;
import com.inspur.edp.web.command.component.metadata.CmpMethodParamConfig;
import com.inspur.edp.web.command.component.metadata.CmpMethodRefering;
import com.inspur.edp.web.command.component.metadata.ConditionType;
import com.inspur.edp.web.command.component.metadata.EditorContext;
import com.inspur.edp.web.command.component.metadata.EditorInfo;
import com.inspur.edp.web.command.component.metadata.ExtendProperty;
import com.inspur.edp.web.command.component.metadata.Parameter;
import com.inspur.edp.web.command.component.metadata.WebCommand;
import com.inspur.edp.web.command.component.metadata.WebCommandsMetadata;
import com.inspur.edp.web.command.component.utils.ObjectMapperUtil;

import java.util.HashMap;
import java.util.List;

/**
 * @author Kaixuan Shi
 * @version 0.1
 */
public class ComponentInit {
    public static WebCommandsMetadata get() {
        WebCommandsMetadata component = new WebCommandsMetadata();
        component.setId("id");
        component.setCode("code");
        component.setName("name");
        component.setDescription("des");
        ExtendProperty extendProperty = new ExtendProperty();
        extendProperty.setCommon(true);
        extendProperty.setFormCode("formCode");
        component.setExtendProperty(extendProperty);
        component.getOperations().add(getCommand());
        component.getOperations().add(getCommand());
        return component;
    }

    public static WebCommand getCommand() {
        WebCommand command = new WebCommand();
        command.setId("id");
        command.setCode("code");
        command.setName("name");
        command.setDescription("des");
        command.getCompParameters().add(getParameter());
        command.getCompParameters().add(getParameter());
        command.getItems().add(getBranchCollectionItem());
        command.getItems().add(getBranchCommandItem());
        command.getItems().add(getCmpMethodReferingItem());
        return command;
    }

    private static CmpMethodRefering getCmpMethodReferingItem() {
        CmpMethodRefering refer = new CmpMethodRefering();
        refer.setId("id");
        refer.setCode("code");
        refer.setName("name");
        refer.setMethodId("methodId");
        refer.setMethodCode("methodCode");
        refer.setMethodName("methodName");
        refer.setComponentId("componentId");
        refer.setComponentCode("componentCode");
        refer.setComponentName("componentName");
        refer.setComponentPath("componentPath");
        refer.setReplaced(true);
        refer.setAfterExpansion(true);
        refer.setBeforeExpansion(true);
        List<CmpMethodParamConfig> paramConfigs = refer.getParamConfigs();
        CmpMethodParamConfig config = new CmpMethodParamConfig();
        config.setParamExpress("express");
        config.setParamName("name");
        config.setParamCode("code");
        paramConfigs.add(config);
        paramConfigs.add(config);
        return refer;
    }

    private static BranchCommandItem getBranchCommandItem() {
        BranchCommandItem commandItem = new BranchCommandItem();
        commandItem.setId("id");
        commandItem.setCode("code");
        commandItem.setName("name");
        commandItem.setExpress("express");
        commandItem.setConditionType(ConditionType.ELSEIF);
        commandItem.getItems().add(getCmpMethodReferingItem());
        commandItem.getItems().add(getCmpMethodReferingItem());
        return commandItem;
    }

    private static BranchCollectionCommandItem getBranchCollectionItem() {
        BranchCollectionCommandItem collectionItem = new BranchCollectionCommandItem();
        collectionItem.setId("id");
        collectionItem.setCode("code");
        collectionItem.setName("name");
        List<BranchCommandItem> items = collectionItem.getItems();
        items.add(getBranchCommandItem());
        items.add(getBranchCommandItem());
        return collectionItem;
    }

    private static Parameter getParameter() {
        Parameter param = new Parameter();
        param.setId("id");
        param.setCode("code");
        param.setName("name");
        param.setDescription("des");
        param.setParamType("paramType");
        param.setRetVal(true);
        param.setEditorType("editorType");
        param.setDefaultValue("default");
        EditorInfo editorInfo = new EditorInfo();
        editorInfo.setType("editorType");
        param.setCustomControlSource(editorInfo);
        HashMap<String, EditorContext> map = new HashMap<>();
        editorInfo.setContext(map);
        EditorContext context = new EditorContext();
        map.put("data", context);
        context.setType("string");
        context.setValue("Component");
        map.put("columns", context);
        return param;
    }
}
